#ifndef __USER_CODEC_H__
#define __USER_CODEC_H__

#include "audio_element.h"
#include "audio_event_iface.h"
#include "audio_hal.h"
#include "audio_mem.h"
#include "audio_pipeline.h"
#include "board.h"
#include "esp_err.h"
#include "fatfs_stream.h"
#include "i2s_stream.h"

#define AUDIO_SOURCE_NUM 2
typedef enum {
    AUDIO_SOURCE_BT = 0,
    AUDIO_SOURCE_BLE,
} audio_source_type_t;

typedef struct {
    bool enable;
    audio_source_type_t source;
    void *data;
} audio_source_config_t;

typedef int (*audio_output_get_data)(char *buffer, int size);

audio_element_handle_t debug_stream_init();
void opus_test(void);
void opus_decoding_task(void *param);
void opus_encoding_task(void *param);
void mic_to_opus_log_task(void *param);

esp_err_t user_codec_init(void);
esp_err_t user_codec_set_volume(int vol);
void user_set_i2s_clk(int clk, int bits, int ch);

extern audio_hal_handle_t s_codec_hal;

// record
typedef void (*encoder_process)(audio_element_state_t state, uint8_t *data, int len);

#define AUDIO_SINK_NUM 2
typedef enum {
    AUDIO_SINK_BT = 0,
    AUDIO_SINK_BLE,
} audio_sink_type_t;

typedef struct {
    bool enable;
    audio_sink_type_t source;
    void *data;
} audio_sink_config_t;

void record_task(void *param);
void record_reconfigure(audio_sink_config_t config);
void record_regist_handler(encoder_process process);
extern audio_element_handle_t i2s_reader;

// player
typedef int (*decoder_data_in)(uint8_t *data, int len);

void player_task(void *param);
void userDataIn_regist_handler(decoder_data_in handler);
void player_reconfigure(audio_source_config_t config);

extern audio_element_handle_t i2s_writer;

#endif //__USER_CODEC_H__